from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE `menu_role` (
    `menu_id` INT NOT NULL REFERENCES `menu` (`id`) ON DELETE CASCADE,
    `role_id` INT NOT NULL REFERENCES `role` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='角色菜单';
        CREATE TABLE `user_role` (
    `role_id` INT NOT NULL REFERENCES `role` (`id`) ON DELETE CASCADE,
    `user_id` INT NOT NULL REFERENCES `user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='用户角色';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS `user_role`;
        DROP TABLE IF EXISTS `menu_role`;"""
